﻿namespace Hotel.Module.Management.Models
{
    using Enities = Hotel.Module.Management.DataRepository;
    using System;

    public class Assignment : Model.Infrastructure.IDistributedStorageEntity
    {

        /// <summary>
        /// Creates a new Assignment instance on Entuty type
        /// </summary>
        /// <param name="entity">Entity assignment object from wich new Assignment instance will be created</param>
        public static Assignment FromEnityModel(Enities.Assignment entity)
        {
            Assignment result = new Assignment();
            if (entity == null)
            {
                return null;
            }
            else
            {
                result.Description = entity.Description;
                result.ID = entity.Id;
                result.RoomNumber = entity.RoomNumber;
                result.ServiceID = entity.ServiceID;
                result.WorkerLogin = entity.WorkerLogin;
                result.WorkerType = (CurrentWorkerType)entity.WorkerType;
                result.State=(AssignmentState)entity.State;               
            }
            return result;
        }

        /// <summary>
        /// Description of the current assignment
        /// </summary>        
        public string Description { get; set; }

        /// <summary>
        /// current state of assignment
        /// </summary>     
        public AssignmentState State { get; set; }

        /// <summary>
        /// Identificational number of assignment
        /// </summary>     
        public int ID { get; set; }

        /// <summary>
        /// Login of the worker who made or applied the assignment
        /// </summary>     
        public string WorkerLogin { get; set; }

        /// <summary>
        /// The type of worker to which this assignment is commnted
        /// </summary>   
        public CurrentWorkerType WorkerType { get; set; }

        public enum CurrentWorkerType
        {
            Cleaners, Repairman
        }
        /// <summary>
        /// Room in which assignment is to be made
        /// </summary>
         public int RoomNumber { get; set; }

        /// <summary>
        /// ServiceID which have to be made
        /// </summary>       
        public int ServiceID { get; set; }

        public string PartitionKey { get; set; }

        public string RowKey { get; set; }

        public System.DateTime Timestamp { get; set; }

        /// <summary>
        /// Assignes data in cur instance to some object
        /// </summary>
        /// <param name="obj">object to which data will be assigned</param>
        public void AssignTo(object obj)
        {
            if (obj is Enities.Assignment)
            {
                Enities.Assignment result = obj as Enities.Assignment;
                result.Description = Description;
                result.Id = ID;
                result.RoomNumber = RoomNumber;
                result.ServiceID = ServiceID;
                result.WorkerLogin = WorkerLogin;
                result.WorkerType = (int)WorkerType;
                result.State = (int)State;
                return;
            }
            throw new ArgumentException();
        }
    }
}
